
window.onload = function () {
    clockStart();
}

function clockStart() {
    var today = new Date();
    var h = today.getHours()
    var m = today.getMinutes()
    var s = today.getSeconds()
    var a = document.getElementsByTagName('img');
    if (m < 10) {
        m = "0" + m.toString();
    }
    if (s < 10) {
        s = "0" + s.toString();
    }
    console.log(a[0].getAttribute("src"))
    if (a[0].getAttribute("src") == "head1.png") {
    if (h < 10) {
        h = "0" + h.toString();
    }
        if (h > 12) {
            h = h - 12;
    if (h < 10) {
        h = "0" + h.toString();
    }
            document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s + " pm";
        }
        else {
            document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s + " am";
        }
    } else { document.getElementById("txt_clock").innerHTML = h + ":" + m + ":" + s; }

    t = setTimeout("clockStart()", 500)
}

var counter = 0
var flag = false
var timerLock = false

/**
 * 计时器启动
 */
function timerStart() {
    if(timerLock)
        return
    timerLock = true
    flag = true;
    console.log(flag);
    timer();
}

/**
 * 计时
 */
function timer() {
    if(counter === 15)
        alert((document.getElementsByTagName("img")[0].getAttribute("src") === "head1.png" ? "男生" : "女生") + " - " + document.getElementById("txt_clock").innerHTML);
    if (!flag)
        return;
    document.getElementById("timer_txt").value = ++counter;
    setTimeout("timer()", 1000);
}

/**
 * 暂停
 */
function timerStop() {
    flag = false
    timerLock = false
}

/**
 * 关闭计时器
 */
function timerClose() {
    timerStop();
    counter = 0;
    document.getElementById("timer_txt").value = counter;
}
function changeHead(){
        var head=document.getElementById("head");
        var src=head.getAttribute("src")
        console.log(src);
        if(src==='head1.png'){
            head.setAttribute("src","head2.png");
            alert(counter);
        }else{
            head.setAttribute("src","head1.png");
            alert(counter);
        }
}
